<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<div class="container-fluid" (window:resize)="onResize($event)">
  <div class="row">
    <h5 class="over-title margin-bottom-15">Create Measure</h5>
  </div>
  <div class="row">
    <form name="Form" id="form" #prForm="ngForm" novalidate>
      <div id="wizard" class="swMain">
        <ul>
          <li (click)="goTo(1)">
            <a [ngClass]="{'selected' : currentStep >= 1, 'done' : currentStep > 1}" class="selected">
              <div class="stepNumber">
                1
              </div>
              <span class="stepDesc text-small"> Choose Source </span>
            </a>
          </li>
          <li (click)="goTo(2)">
            <a [ngClass]="{'selected' : currentStep >= 2, 'done' : currentStep > 2}" class="" style="">
              <div class="stepNumber">
                2
              </div>
              <span class="stepDesc text-small"> Select Models </span>
            </a>
          </li>
          <li (click)="goTo(3)">
            <a [ngClass]="{'selected' : currentStep >= 3, 'done' : currentStep > 3}">
              <div class="stepNumber">
                3
              </div>
              <span class="stepDesc text-small">Partition Configuration </span>
            </a>
          </li>
          <li (click)="goTo(4)">
            <a [ngClass]="{'selected' : currentStep >= 4, 'done' : currentStep > 4}">
              <div class="stepNumber">
                4
              </div>
              <span class="stepDesc text-small"> Configuration </span>
            </a>
          </li>
        </ul>
      </div>
      <div id="step-1" *ngIf="currentStep == 1" class="formStep">
        <label class="stepDesc">This step let you choose the single source of truth for data quality comparision with target. Currently you can only select the attributes from one schema</label>
        <div class="container-fluid">
          <div class="col-md-4 col-lg-4 col-sm-4">
            <fieldset>
              <legend>Please select schema</legend>
              <tree-root [nodes]="nodeList" [options]="options"></tree-root>
            </fieldset>
          </div>
          <div class="col-md-8 col-lg-8 col-sm-8">
            <fieldset>
              <legend>
                Select attributes
              </legend>
              <div class="y-scrollable">
                <div style="margin-top:10px;">
                  <label>View schema:</label>
                  <i style="color:#fff;font-weight: bold;">{{currentDBstr}}{{currentTable}}
                    </i>
                </div>
                <div style="margin-top:5px;">
                  <table class="table table-striped no-border">
                    <thead>
                      <tr style="background-color:#7D95CC">
                        <th>
                          <input type="checkbox" (click)="toggleAll()" [checked]="selectedAll" />
                        </th>
                        <th>Column Name</th>
                        <th>Type</th>
                        <th>Comment</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr *ngIf="!schemaCollection || schemaCollection.length == 0">
                        <td colspan="5" style="text-align:center;"><span class="highlight">Please select a schema from the left tree first</span></td>
                      </tr>
                      <tr *ngFor="let row of schemaCollection">
                        <td>
                          <input type="checkbox" (click)='toggleSelection(row)' [checked]="row.selected" value={{row.name}} />
                        </td>
                        <td>{{row.name}}</td>
                        <td>{{row.type}}</td>
                        <td>{{row.comment}}</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </fieldset>
          </div>
          <div class="form-group btn-container">
            <toaster-container></toaster-container>
            <button class="btn btn-primary btn-o next-step btn-wide pull-right" (click)="next(Form)">
              Next <i class="fa fa-arrow-circle-right"></i>
            </button>
          </div>
        </div>
      </div>
      <div id="step-2" *ngIf="currentStep == 2" class="formStep">
        <label class="stepDesc">Please choose one of the profiling models provided below:</label>
        <div class="container-fluid" id="notshowrule">
          <div class="col-md-12 col-lg-12 col-sm-12">
            <!-- <fieldset style="max-height:400px;overflow-y:scroll;"> -->
            <fieldset>
              <div class="y-scrollable">
                <div style="display:block">
                  <label style="margin-left:15px">View schema:</label> <i style="color:#fff;font-weight: bold;">{{currentDB}}.{{currentTable}}</i>
                </div>
                <div class="col-md-12 col-lg-12 col-sm-12" style="z-index:100;margin-top:5px;">
                  <table class="table table-striped" [mfData]="results" #mf="mfDataTable">
                    <thead>
                      <tr style="background-color:#7D95CC">
                        <th>Column Name</th>
                        <th>Data Type</th>
                        <th>Rule&nbsp;&nbsp;&nbsp;&nbsp;<i style="color:#b2c831;" class="fa fa-question-circle fa-lg"></i><i style="font-family: 'Open Sans', sans-serif;">Click <a (click)="showRule()" class="bark-link po">here</a> to view the rule definition</i></th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr *ngFor="let item of selection">
                        <td class="middle">{{item.name}}</td>
                        <td class="middle">{{item.type}}</td>
                        <td class="col-md-5 middle">
                          <angular2-multiselect [data]="dropdownList[item.name]" name="rules-{{item.name}}" [(ngModel)]="selectedItems[item.name]" [settings]="dropdownSettings"></angular2-multiselect>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                <!-- <div *ngFor="let index of transrule">&nbsp;&nbsp;&nbsp;&nbsp;{{index}}</div> -->
              </div>
            </fieldset>
          </div>
          <div class="form-group btn-container">
            <button class="btn btn-primary btn-o back-step btn-wide pull-left" (click)="prev(Form)">
              <i class="fa fa-arrow-circle-left"></i> Back
            </button>
            <toaster-container></toaster-container>
            <button class="btn btn-primary btn-o next-step btn-wide pull-right" (click)="next(Form)">
              Next <i class="fa fa-arrow-circle-right"></i>
            </button>
          </div>
        </div>
        <div class="container-fluid formStep" id="showrule" style="display:none;">
          <div class="col-md-12 col-lg-12 col-sm-12">
            <fieldset>
              <app-rule></app-rule>
            </fieldset>
          </div>
          <div class="form-group btn-container">
            <button class="btn btn-primary btn-o back-step btn-wide pull-left" (click)="back()">
              <i class="fa fa-arrow-circle-left"></i> Back
            </button>
          </div>
        </div>
      </div>
      <div id="step-3" *ngIf="currentStep == 3" class="formStep">
        <label class="stepDesc">Please complete the partition configuration for {{currentTable}}</label>
        <div class="container-fluid">
          <div class="col-md-12 col-lg-12 col-sm-12">
            <fieldset>
              <legend>
                Required Information
              </legend>
              <div class="y-scrollable">
                <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group" style="text-align:center">
                    Data Source:{{currentDB}}.{{currentTable}}
                  </div>
                  <app-configuration [data]="config" [location]="srclocation" (event)="getData($event)"></app-configuration>
                </div>
              </div>
            </fieldset>
          </div>
          <div class="form-group btn-container">
            <button class="btn btn-primary btn-o back-step btn-wide pull-left" (click)="prev(Form)">
              <i class="fa fa-arrow-circle-left"></i> Back
            </button>
            <toaster-container></toaster-container>
            <button class="btn btn-primary btn-o next-step btn-wide pull-right" (click)="next(Form)">
              Next <i class="fa fa-arrow-circle-right"></i>
            </button>
          </div>
        </div>
      </div>
      <div id="step-4" *ngIf="currentStep == 4" class="formStep">
        <label class="stepDesc">Please setup the measure required information</label>
        <div class="container-fluid">
          <div class="col-md-12 col-lg-12 col-sm-12">
            <fieldset>
              <legend>
                Required Information
              </legend>
              <div class="y-scrollable">
                <div class="col-md-12 col-lg-12 col-sm-12" style="margin-top:30px;">
                  <div class="form-group" [ngClass]="{'has-error':prName.dirty&&prName.invalid, 'has-success':prName.valid}">
                    <label class="col-md-2 col-lg-2 col-sm-2 control-label">
                      Measure Name<span class="symbol required"></span>:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10 ">
                      <input type="text" class="form-control" [(ngModel)]="name" #prName="ngModel" name="prName" placeholder="Please input the measure name" required pattern="^[a-zA-Z0-9_-]*$">
                      <span class="error text-small block " *ngIf="prName.dirty && (prName.errors?.required)">Measure Name is required</span>
                      <span class="error text-small block " *ngIf="prName.dirty && (prName.errors?.pattern)">Only letter, number, "-" and "_" are allowed</span>
                    </div>
                  </div>
                </div>
                <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group">
                    <label class="col-md-2 col-lg-2 col-sm-2 control-label">
                      Measure Description:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10 ">
                      <input type="text" class="form-control" [(ngModel)]="desc" placeholder="Please input detailed description of your measure" name="desc">
                    </div>
                  </div>
                </div>
                <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group">
                    <label for="typeSelector" class="col-md-2 col-lg-2 col-sm-2 control-label">
                      Measure Type:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10 ">
                      <select id="typeSelector" class="form-control" [(ngModel)]="type" disabled required name="type">
                        <option>{{type}}</option>
                      </select>
                    </div>
                  </div>
                </div>
                <!-- <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group">
                    <label for="systemSelector" class="col-md-2 col-lg-2 col-sm-2 control-label">
                      Organization<span class="symbol required"></span>:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10 ">
                      <input type="text" id="systemSelector" class="form-control" required ng-pattern="'([0-9a-zA-Z\\_\\-])+'" name="org" [(ngModel)]="org">
                    </div>
                  </div>
                </div> -->
                <!-- <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group">
                    <label for="systemSelector" class="col-md-2 col-lg-2 col-sm-2 control-label">
                      Group:<span class="symbol required"></span>:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10 ">
                      <tag-input class="form-control" style="height: 44px;padding: 0 6px;" id="systemSelector" required [(ngModel)]='grp' [editable]='true' name="grp"></tag-input>
                    </div>
                  </div>
                </div> -->
                <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group">
                    <label class="col-md-2 col-lg-2 col-sm-2 control-label">
                      DataSource:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10">
                      <input type="text" class="form-control" name="DataAsset" value="{{currentTable}}" disabled>
                    </div>
                  </div>
                </div>
                <div class="col-md-12 col-lg-12 col-sm-12">
                  <div class="form-group">
                    <label class="col-md-2 col-lg-2 col-sm-2 control-label">
                      Owner:
                    </label>
                    <div class="col-md-10 col-lg-10 col-sm-10">
                      <input type="text" class="form-control" name="owner" disabled [(ngModel)]="owner">
                    </div>
                  </div>
                </div>
              </div>
              <div style="color:#b2c831">
                <p>
                  <i class="fa fa-info-circle"></i> After submitted, please go to "<a class="bark-link" routerLink="/measures">Measures</a>" to check the measure status
                </p>
              </div>
            </fieldset>
          </div>
          <div class="form-group btn-container">
            <button class="btn btn-primary btn-o back-step btn-wide pull-left" (click)="prev(Form)">
              <i class="fa fa-arrow-circle-left"></i> Back
            </button>
            <toaster-container></toaster-container>
            <button type="submit" (click)="submit(prForm)" class="btn btn-primary btn-o next-step btn-wide pull-right">
              Submit
            </button>
          </div>
        </div>
      </div>
      <div class="modal fade" id="confirm" role="dialog" #modal tabindex="-1" [ngClass]="{'in': visibleAnimate}" [ngStyle]="{'display': visible ? 'block' : 'none', 'opacity': visibleAnimate ? 1 : 0}" (click)="onContainerClicked($event)">
        <div class="modal-dialog modal-xg modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" (click)="hide()">&times;</button>
              <h4 class="modal-title">Save the measure with the below information?</h4>
            </div>
            <div class="modal-body">
              <div class="container-fluid" id="viewruleContent" style="overflow:auto;">
                <div class="row">
                  <h5 class="over-title margin-bottom-15">Basic information</h5>
                </div>
                <div class="row">
                  <div class="col-lg-12 col-md-12 col-sm-12">
                    <div id="viewrule-definition" class="viewrule-content">
                      <div class="row">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Measure Name:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8 ">
                          {{name}}
                        </div>
                      </div>
                      <div class="row">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Measure Description:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8 ">
                          {{desc}}
                        </div>
                      </div>
                      <div class="row">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Measure Type:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8 ">
                          {{type}}
                        </div>
                      </div>
                      <div class="row">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          DataSource:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8">
                          {{currentDB}}.{{currentTable}}
                        </div>
                      </div>
                      <div class="row" *ngIf="this.size">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Source Partition Size:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8">
                          {{this.size}}
                        </div>
                      </div>
                      <div class="row" *ngIf="this.size">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Source Time Zone:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8">
                          {{this.timezone}}
                        </div>
                      </div>
                      <div class="row" *ngIf="this.where">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Source Where:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8">
                          {{this.where}}
                        </div>
                      </div>
                      <div class="row" *ngIf="this.needpath && this.path">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Source Path:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8">
                          {{this.path}}
                        </div>
                      </div>
                      <div class="row">
                        <label class="col-md-4 col-lg-4 col-sm-4">
                          Owner:
                        </label>
                        <div class="col-md-8 col-lg-8 col-sm-8">
                          {{owner}}
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <h5 class="row">Rules</h5>
                <div class="row" *ngFor="let index of noderule;">
                  &nbsp;&nbsp;&nbsp;&nbsp;{{index.name}}&nbsp;:&nbsp;{{index.infos}}
                </div>
                <br/>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" (click)="hide()">Cancel</button>
              <button type="button" id="save" class="btn btn-primary" (click)="save()">Save</button>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
